package com.gl.order.controller;

import com.gl.order.commom.ResultBean;
import com.gl.order.service.ProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import java.util.List;

/**
 * @Author: zhoujian
 * @Date: 2021/6/22 14:52
 * @ClassName: RoleController
 */
@Api(tags = "流程管理queryDbsxData")
@RestController
@RequestMapping("/process")
@Slf4j
public class ProcessController {


    private ProcessService processService;

    @Autowired
    public ProcessController(ProcessService processService) {
        this.processService = processService;
    }



    @PostMapping("/saveOrUpdateLc")
    @ApiOperation("新增或修改流程")
    public ResultBean saveOrUpdateLc(@RequestBody Map<String,String> paramMap) {
        log.info("saveOrUpdateLc----->pram:" + paramMap);
        processService.saveOrUpdateLc(paramMap);
        return ResultBean.success();
    }

    @PostMapping("/saveOrUpdateLcJd")
    @ApiOperation("新增或修改流程节点")
    public ResultBean saveOrUpdateLcJd(@RequestBody Map<String,String> paramMap){
        log.info("saveOrUpdateLcJd----->pram:" + paramMap);
        processService.saveOrUpdateLcJd(paramMap);
        return ResultBean.success();
    }

    @GetMapping("/queryLcJdInfo")
    @ApiOperation("查询流程信息")
    public ResultBean queryLcJdInfo(String zbwid){
        return processService.queryProcessInfo(zbwid);
    }

    @PostMapping("/auditProcess")
    @ApiOperation("审核流程")
    public ResultBean auditProcess(@RequestBody Map<String,Object> param){
        try {
            processService.auditProcess(param);
            return ResultBean.success();
        } catch (Throwable throwable) {
            log.error("审核流程失败",throwable);
            return ResultBean.failed(throwable.getMessage());
        }
    }


    @PostMapping("/queryDbsxData")
    @ApiOperation("查询代办数据")
    public ResultBean queryDbsxData(@RequestBody Map<String,Object> paramMap) {
        Boolean flag = null != paramMap.get("SHIPMENT_TIME");
        List<String> SHIPMENT_TIME = flag ? (List<String>) paramMap.get("SHIPMENT_TIME") : new ArrayList();
        if (null != SHIPMENT_TIME && !SHIPMENT_TIME.isEmpty()) {
            paramMap.put("SHIPMENT_TIME_START", SHIPMENT_TIME.get(0));
            paramMap.put("SHIPMENT_TIME_END", SHIPMENT_TIME.get(1));
        }
        return processService.queryDbsxData(paramMap);
    }

    @GetMapping("/queryConfigColumns")
    @ApiOperation("查询配置")
    public ResultBean queryConfigColumns(String jdwid) {
        return processService.queryConfigColumns(jdwid);
    }

    @PostMapping("/excel/export")
    public void excelExport(HttpServletResponse response, @RequestBody Map<String,Object> paramMap) throws IOException {
        processService.excelExport(response,paramMap);
    }
}
